package com.hexinfo.dmpro.xxljob.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.xxljob.model.JobContact;
import com.hexinfo.dmpro.xxljob.service.JobContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 调度任务记录表
 *
 * @author zhou
 * @date 2023-09-08 10:45:22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/jobcontact" )
@Api(value = "jobcontact", tags = "调度任务记录表管理")
public class JobContactController {

    private final JobContactService jobContactService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param jobContact 调度任务记录表
     * WrapperEnhancer.like(jobContact); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public ResponseEntity<Object> getJobContactPage(Page page, JobContact jobContact) {
        return ResponseEntity.ok(jobContactService.queryList(page,jobContact));
    }


    /**
     * 通过id查询调度任务记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(jobContactService.getById(id));
    }

    /**
     * 新增调度任务记录表
     * @param jobContact 调度任务记录表
     * @return R
     */
    @ApiOperation(value = "新增调度任务记录表", notes = "新增调度任务记录表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody JobContact jobContact) {
        return ResponseEntity.ok(jobContactService.save(jobContact));
    }

    /**
     * 修改调度任务记录表
     * @param jobContact 调度任务记录表
     * @return R
     */
    @ApiOperation(value = "修改调度任务记录表", notes = "修改调度任务记录表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody JobContact jobContact) {
        return ResponseEntity.ok(jobContactService.updateById(jobContact));
    }

    /**
     * 通过id删除调度任务记录表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除调度任务记录表", notes = "通过id删除调度任务记录表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(jobContactService.removeById(id));
    }

}
